//
//  YHEmotionManager.swift
//  EmotionKeyboard
//
//  Created by 昱含 on 16/5/31.
//  Copyright © 2016年 YuHan. All rights reserved.
//

import UIKit

class YHEmotionManager: NSObject {
    
    lazy var packages: [YHEmotionPackage] = [YHEmotionPackage]()
     static let sharedEmotion: YHEmotionManager = YHEmotionManager()
    private override init() {
        super.init()
        loadAllEmotions()
    }
    
    func loadAllEmotions() {
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")!
        let dict = NSDictionary(contentsOfFile: path)!
        let package = dict["packages"] as! [[String : AnyObject]]
        for item in package {
            let id = item["id"] as! String
            loadSectionEmotions(id)
        }
               
    }
    
    private func loadSectionEmotions(id: String) {
        let path = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: "Emoticons.bundle/" + id)!
        let dict = NSDictionary(contentsOfFile: path)!
        let name = dict["group_name_cn"] as! String
        let emotionsArr = dict["emoticons"] as! [[String : String]]
        let p = YHEmotionPackage(id: id, name: name, array: emotionsArr)
        packages.append(p)
      
    }

}
